package org.example.teacher.controller;

import org.example.teacher.Service.TeacherService;
import org.example.teacher.entity.teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

//Controller -- 返回是视图； 使用restController，返回字符串对象
@RestController
@RequestMapping("/api")
public class apiController {

    @Autowired
    TeacherService teacherService;

    @RequestMapping("/teacherDelete")
    public Integer teacherDelete(@RequestParam String id) {
        teacher teacher = new teacher();
        teacher.setId(Integer.valueOf(id));
//        1.调用service的删除方法
        if (teacherService.delete(teacher) == 1) {
            return 1;
        } else {
            return 0;
        }
    }

    //    处理更新操作
    @RequestMapping("/teacherUpdateProcess")
    public Integer teacherUpdateProcess(@RequestParam String id, @RequestParam String name, @RequestParam String age) {
//        1.组装成teacher实体
        teacher teacher = new teacher(Integer.valueOf(id), name, age);
        if (teacherService.update(teacher)==1){
            return 1;
        }else {
            return 0;
        }
    }
}

